package org.example.impl;

import org.example.pojo.clientInfo;
import org.example.tools.utilsTools;

import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

/**
 * clientListenerThread
 * 客户端上线监听
 */
public class clientListenerThread implements Runnable{

    private ServerSocket serverSocket;
    public ServerSocket getServerSocket() {
        return serverSocket;
    }

    public void setServerSocket(ServerSocket serverSocket) {
        this.serverSocket = serverSocket;
    }
    @Override
    public void run() {
        while (true){
            synchronized (clientListenerThread.class){
                try {
                    Socket socket = this.getServerSocket().accept();
                    //监听事件客户连接以后, 添加配置到
                    List<String> UserInfo = new ArrayList<>();
                    UserInfo.add("ALL");
                    utilsTools.UserMaps.put(socket,new clientInfo(UserInfo,0));
                    System.out.println("当前在线用户数:" + utilsTools.UserMaps.size() + "位");
                    utilsTools.threadPoolExecutor.submit(new clientDataMessageImpl());
                }catch (Exception e){break;}
            }
        }
    }
}
